package ru.hh.school;

import java.util.HashSet;

public class UserManager {
    private final HashSet<String> nicks;

    public UserManager() {
        nicks = new HashSet<String>();
    }

    public synchronized void giveBackNick(String nick) {
        nicks.remove(nick);
    }

    public synchronized boolean tryTakeNick(String oldNick, String newNick) {
        if (nicks.contains(newNick)) {
            return false;
        }
        if (oldNick != null) {
            nicks.remove(oldNick);
        }
        nicks.add(newNick);
        return true;
    }
}
